﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Ajax
{
    /// <summary>
    /// 用户控件中用到的Ajax方法
    /// </summary>
    public class Control
    {
        public Control()
        {
        }

        /// <summary>
        /// 提交在线投票
        /// </summary>
        /// <param name="sID">如: 2|3|4...</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public static void UpdateSurvey(string sID)
        {
            DAL.Tables.tbl_Site_OnlineSurvey table = new DAL.Tables.tbl_Site_OnlineSurvey();

            string[] sList = sID.Trim().Split('|');

            for (int i = 0; i < sList.Length; i++)
            {
                long ID = Shove._Convert.StrToLong(sList[i].ToString(), 0);

                if (ID > 0)
                {
                    Shove.Database.MSSQL.ExecuteSQLScript("update tbl_Site_OnlineSurvey set Amount = Amount + 1 where ID = " + ID);
                }
            }
        }

        /// <summary>
        /// 获取商品类别下的所有子类别
        /// </summary>
        /// <param name="GoodTypeID"> 类别ID </param>
        /// <returns> JSon 数据格式 </returns>
        [AjaxPro.AjaxMethod]
        public static string GetChildGoodTypeByID(string GoodTypeID)
        {
            string Result = "";
            string Condition = "ID like '" + GoodTypeID + "%'";

            DataTable dt = new DAL.Tables.tbl_Shop_GoodType().Open("ID,TypeName", Condition, "");

            if (dt != null && dt.Rows.Count > 0)
            {
                Result = Utility.JSon.DataTableToJSon(dt,"ChildGoodType");
            }

            return Result;
        }

        /// <summary>
        /// 根据ID获取邮费
        /// </summary>
        /// <param name="ID"></param>        
        [AjaxPro.AjaxMethod]
        public static string GetCarriageTypeMoneyByID(string sID)
        {
            string Result = "";
            int ID = Shove._Convert.StrToInt(sID, 0);

            DataTable dt = null;
            dt = new DAL.Tables.tbl_Site_CarriageType().Open("", "[ID]=" + ID, "");

            if (dt != null && dt.Rows.Count > 0)
            {
                Result = dt.Rows[0]["Money"].ToString();
            }

            return Result;
        }

    }    

}